<template>
  <div class="login_container">
    <div class="login_box">
      <!-- 头像区域 -->
      <div></div>
      <!-- 登录表单区域 -->
      <el-form :model="loginForm"
               :rules="loginFormRules"
               ref="loginFormRef"
               class="login_form">
        <el-form-item prop="username">
          <el-input prefix-icon="iconfont icon-user"
                    v-model="loginForm.username"
                    placeholder="请输入账号"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input prefix-icon="iconfont icon-3702mima"
                    v-model="loginForm.password"
                    type="password"
                    placeholder="请输入密码"></el-input>
        </el-form-item>
        <el-form-item class="btns">
          <el-button type="primary"
                     @click="login"
                     round>登录</el-button>
          <el-button type="info"
                     @click="resetLoginForm"
                     round>重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      loginForm: {
        username: 'admin',
        password: '123456'
      },
      loginFormRules: {
        username: [
          { required: true, message: '请输入登录名称', trigger: 'blur' },
          { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
        ],
        // 验证密码是否合法
        password: [
          { required: true, message: '请输入登录密码', trigger: 'blur' },
          { min: 6, max: 15, message: '长度在 6 到 15 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  created () {

  },
  mounted () {

  },
  methods: {
    // 点击重置按钮，重置登录表单
    resetLoginForm () {
      this.$refs.loginFormRef.resetFields()
    },
    login () {
      if (this.loginForm.username === 'admin' && this.loginForm.password === '123456') {
        this.$router.push('/home')
      } else {
        this.$message.error('登录名或密码错误')
      }
    }
  }
}
</script>

<style scoped lang="less">
.login_container {
  height: 100%;
  background: url('../assets/login01.jpeg') no-repeat;
  background-size: cover;
  .login_box {
    width: 450px;
    height: 300px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 10px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
  }
  .btns {
    display: flex;
    justify-content: center;
  }
  .login_form {
    position: absolute;
    top: 80px;
    width: 100%;
    padding: 0 40px;
    box-sizing: border-box;
  }
}
</style>
